
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import javax.swing.*;
import java.sql.*;

final class EditItem extends javax.swing.JInternalFrame {
    PreparedStatement statement;
    ResultSet result;
    Systems systems=new Systems();
    Thread editItemThread=new Thread();
    Thread editItemTitleThread=new Thread();

    String dbName="";
    String dbDescription="";
    String dbPrice="";
    String dbCategoryCode="";
    String dbCategory="";
    String dbLocationCode="";
    String dbLocation="";
    String dbType="";
    String dbTax="";

    /** Creates new form Customer */
     EditItem() {
        initComponents();
            /* Create and display the form */
            editItemThread=new Thread(new Runnable() {
                public void run() {
                    disableControls();
                    resetCombo();
                }
            });
            editItemTitleThread=new Thread(new Runnable() {
                public void run() {
                    while(editItemThread.isAlive())setProcessingTitle(editItemTitleThread);
                    enableControls();
                    System.out.println("companyThread stopped runing.");
                }
            });
            editItemThread.start();
            editItemTitleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jAddressLabel = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLocationComboBox = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jDescriptionTextArea = new javax.swing.JTextArea();
        jUpdateButton = new javax.swing.JButton();
        jNameTextField = new javax.swing.JTextField();
        jPriceTextField = new javax.swing.JTextField();
        jTypeTextField = new javax.swing.JTextField();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        itemCodeComboBox = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jCategoryComboBox = new javax.swing.JComboBox();
        jTaxTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jCheckBox4 = new javax.swing.JCheckBox();

        setClosable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(EditItem.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setRequestFocusEnabled(false);
        try {
            setSelected(true);
        } catch (java.beans.PropertyVetoException e1) {
            e1.printStackTrace();
        }
        setVisible(true);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jAddressLabel.setText(resourceMap.getString("jAddressLabel.text")); // NOI18N
        jAddressLabel.setName("jAddressLabel"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLocationComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jLocationComboBox.setEnabled(false);
        jLocationComboBox.setName("jLocationComboBox"); // NOI18N
        jLocationComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jLocationComboBoxActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jDescriptionTextArea.setColumns(20);
        jDescriptionTextArea.setEditable(false);
        jDescriptionTextArea.setLineWrap(true);
        jDescriptionTextArea.setRows(5);
        jDescriptionTextArea.setText(resourceMap.getString("jDescriptionTextArea.text")); // NOI18N
        jDescriptionTextArea.setEnabled(false);
        jDescriptionTextArea.setName("jDescriptionTextArea"); // NOI18N
        jDescriptionTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jDescriptionTextAreaKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(jDescriptionTextArea);

        jUpdateButton.setFont(resourceMap.getFont("jUpdateButton.font")); // NOI18N
        jUpdateButton.setIcon(resourceMap.getIcon("jUpdateButton.icon")); // NOI18N
        jUpdateButton.setText(resourceMap.getString("jUpdateButton.text")); // NOI18N
        jUpdateButton.setName("jUpdateButton"); // NOI18N
        jUpdateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jUpdateButtonActionPerformed(evt);
            }
        });

        jNameTextField.setEditable(false);
        jNameTextField.setText(resourceMap.getString("jNameTextField.text")); // NOI18N
        jNameTextField.setName("jNameTextField"); // NOI18N
        jNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jNameTextFieldActionPerformed(evt);
            }
        });

        jPriceTextField.setEditable(false);
        jPriceTextField.setText(resourceMap.getString("jPriceTextField.text")); // NOI18N
        jPriceTextField.setName("jPriceTextField"); // NOI18N
        jPriceTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jPriceTextFieldKeyTyped(evt);
            }
        });

        jTypeTextField.setEditable(false);
        jTypeTextField.setText(resourceMap.getString("jTypeTextField.text")); // NOI18N
        jTypeTextField.setName("jTypeTextField"); // NOI18N
        jTypeTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTypeTextFieldKeyTyped(evt);
            }
        });

        jCheckBox2.setName("jCheckBox2"); // NOI18N
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        jCheckBox3.setName("jCheckBox3"); // NOI18N
        jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox3ActionPerformed(evt);
            }
        });

        jCheckBox5.setName("jCheckBox5"); // NOI18N
        jCheckBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox5ActionPerformed(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        itemCodeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        itemCodeComboBox.setName("itemCodeComboBox"); // NOI18N
        itemCodeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemCodeComboBoxActionPerformed(evt);
            }
        });

        jButton2.setFont(resourceMap.getFont("jButton2.font")); // NOI18N
        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jCategoryComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jCategoryComboBox.setEnabled(false);
        jCategoryComboBox.setName("jCategoryComboBox"); // NOI18N
        jCategoryComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCategoryComboBoxActionPerformed(evt);
            }
        });

        jTaxTextField.setEditable(false);
        jTaxTextField.setName("jTaxTextField"); // NOI18N
        jTaxTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTaxTextFieldKeyTyped(evt);
            }
        });

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jCheckBox4.setName("jCheckBox4"); // NOI18N
        jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane1)
                                    .addComponent(jNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jCheckBox2))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(itemCodeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jAddressLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel6))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLocationComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jCategoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jPriceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTaxTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCheckBox4)
                                    .addComponent(jCheckBox3)
                                    .addComponent(jCheckBox5))))
                        .addGap(29, 29, 29))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jUpdateButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addGap(52, 52, 52))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jCategoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jCheckBox5)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8)
                                .addComponent(jLocationComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jPriceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel4))
                            .addComponent(jCheckBox3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTaxTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6))
                            .addComponent(jCheckBox4)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(itemCodeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(jAddressLabel))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(70, 70, 70)
                                .addComponent(jCheckBox2)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jUpdateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jNameTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jNameTextFieldActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox2.isSelected())
        {
            jDescriptionTextArea.setEnabled(true);
            jDescriptionTextArea.setEditable(true);
        }
        else
        {
            jDescriptionTextArea.setEnabled(false);
            jDescriptionTextArea.setEditable(false);
            jDescriptionTextArea.setText(dbDescription);

        }
    }//GEN-LAST:event_jCheckBox2ActionPerformed

    private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox3.isSelected())
        {
            jPriceTextField.setEnabled(true);
            jPriceTextField.setEditable(true);
        }
        else
        {
            jPriceTextField.setEnabled(false);
            jPriceTextField.setEditable(false);
            jPriceTextField.setText(dbPrice);

        }
    }//GEN-LAST:event_jCheckBox3ActionPerformed

    private void jCheckBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox5ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox5.isSelected())
        {
            jLocationComboBox.setEnabled(true);
        }
        else
        {
            jLocationComboBox.setEnabled(false);
            if(dbLocation.isEmpty())
            {resetLocation();}
            else{
            jLocationComboBox.setSelectedItem(dbLocation);
            }

        }
    }//GEN-LAST:event_jCheckBox5ActionPerformed

    private void jUpdateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jUpdateButtonActionPerformed
        // TODO add your handling code here:

        if(itemCodeComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select a Item Code ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        if(isCheckBoxesFalse()==false)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," No Data Has Been Edited ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }

        String value=jPriceTextField.getText().trim();

        if(jNameTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Item's Name ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jPriceTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Item's Price ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jTaxTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Item's Tax ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }


         if(systems.isStringDecimal(value)==false)
         {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Item's Price \n    In Money Format","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;

         }
         if(systems.isStringDecimal(jTaxTextField.getText().trim())==false)
         {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Item's Tax \n    In Money Format","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;

         }
        else
        {
            /* Create and display the form */
            editItemThread=new Thread(new Runnable() {
                public void run() {
                    disableControls();
                    submitData();
                    reset();
                }
            });
            editItemTitleThread=new Thread(new Runnable() {
                public void run() {
                    while(editItemThread.isAlive())setProcessingTitle(editItemTitleThread);
                    enableControls();
                    System.out.println("companyThread stopped runing.");
                }
            });
            editItemThread.start();
            editItemTitleThread.start();
        }
    }//GEN-LAST:event_jUpdateButtonActionPerformed
                                      
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. Edit Item - Processing Request");
            thread.sleep(500);
            this.setTitle("::. Edit Item - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. Edit Item - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. Edit Item - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        if(editItemThread.isAlive())
        {
            try{
                editItemThread.stop();
                editItemTitleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle("::. Edit Item");
            enableControls();
        }
        else
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void itemCodeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemCodeComboBoxActionPerformed
        
            /* Create and display the form */
            editItemThread=new Thread(new Runnable() {
                public void run() {
                    disableControls();
                    itemCodeSelected();
                }
            });
            editItemTitleThread=new Thread(new Runnable() {
                public void run() {
                    while(editItemThread.isAlive())setProcessingTitle(editItemTitleThread);
                    enableControls();
                    System.out.println("companyThread stopped runing.");
                }
            });
            editItemThread.start();
            editItemTitleThread.start();
        

    }//GEN-LAST:event_itemCodeComboBoxActionPerformed
    private void itemCodeSelected()
    {
        String itemCode=itemCodeComboBox.getSelectedItem().toString();
        if(itemCode.equals("-- Select --"))
        {
            reset();
        }
        else
        {
        
            dbCategoryCode=systems.getValue(OpenMSApp.Database_A, "Select * from Item where cItemCode= '"+itemCode+"'", "cItemCategoryCode").trim();
            dbLocationCode=systems.getValue(OpenMSApp.Database_A, "Select * from Item where cItemCode= '"+itemCode+"'", "cItemLocationCode").trim();
            dbName=systems.getValue(OpenMSApp.Database_A, "Select * from Item where cItemCode= '"+itemCode+"'", "vName").trim();
            dbDescription=systems.getValue(OpenMSApp.Database_A, "Select * from Item where cItemCode= '"+itemCode+"'", "tDescription").trim();
            dbType=systems.getValue(OpenMSApp.Database_A, "Select * from Item where cItemCode= '"+itemCode+"'", "cType").trim();
            dbPrice=systems.getValue(OpenMSApp.Database_A, "Select * from Item where cItemCode= '"+itemCode+"'", "mPrice").trim();
            dbTax=systems.getValue(OpenMSApp.Database_A, "Select * from Item where cItemCode= '"+itemCode+"'", "mTax").trim();
            dbCategory=systems.getValue(OpenMSApp.Database_A,"Select * from ItemCategory where cItemCategoryCode= '"+dbCategoryCode+"'","vCategoryName");
            dbLocation=systems.getValue(OpenMSApp.Database_A,"Select * from ItemLocation where cItemLocationCode= '"+dbLocationCode+"'","vLocationName");

            jDescriptionTextArea.setText(dbDescription);
            jNameTextField.setText(dbName);
            jTypeTextField.setText(dbType);
            try
            {
                jPriceTextField.setText(systems.converToRealMoneyFormat(dbPrice));
            }
            catch(Exception e)
            {
                jPriceTextField.setText("Er!M1C01K0");
            }
            try
            {
                jTaxTextField.setText(systems.converToRealMoneyFormat(dbTax));
            }
            catch(Exception e)
            {
                jPriceTextField.setText("Er!M1C01K0");
            }
            jLocationComboBox.setSelectedItem(getDbLocation(dbLocation));
            jCategoryComboBox.setSelectedItem(dbCategory);
            resetCheckBoxes();
            disableFields();

        }

    }
    private void jDescriptionTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jDescriptionTextAreaKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jDescriptionTextAreaKeyTyped

    private void jPriceTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPriceTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jPriceTextField.getText();
        if(value.length()>49)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (50) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
        String newValue=String.copyValueOf(value.toCharArray(),0, 49);
        jPriceTextField.setText(newValue);
        }
    }//GEN-LAST:event_jPriceTextFieldKeyTyped

    private void jTypeTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTypeTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jTypeTextField.getText();

        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Do Not Modify ","ERROR !",JOptionPane.ERROR_MESSAGE);

        String newValue=String.copyValueOf(value.toCharArray(),0, value.length()-1);
        jTypeTextField.setText(newValue);
    }//GEN-LAST:event_jTypeTextFieldKeyTyped

    private void jCategoryComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCategoryComboBoxActionPerformed
        // TODO add your handling code here:
        String categoryCode=jCategoryComboBox.getSelectedItem().toString();
        if(categoryCode.equals("-- Select --"))
        {
            resetCategory();
        }
    }//GEN-LAST:event_jCategoryComboBoxActionPerformed

    private void jLocationComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jLocationComboBoxActionPerformed
        // TODO add your handling code here:
        String locationCode=jLocationComboBox.getSelectedItem().toString();
        if(locationCode.equals("-- Select --"))
        {
            resetLocation();
        }
    }//GEN-LAST:event_jLocationComboBoxActionPerformed

private void jTaxTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTaxTextFieldKeyTyped
// TODO add your handling code here:
}//GEN-LAST:event_jTaxTextFieldKeyTyped

private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox4ActionPerformed

        if(jCheckBox4.isSelected())
        {
            jTaxTextField.setEnabled(true);
            jTaxTextField.setEditable(true);
        }
        else
        {
            jTaxTextField.setEnabled(false);
            jTaxTextField.setEditable(false);
            jTaxTextField.setText(dbTax);
        }
}//GEN-LAST:event_jCheckBox4ActionPerformed

     void resetLocation()
    {
        String[] location=systems.getTableDataArray(OpenMSApp.Database_A,"ItemLocation",2);
        location[0]="-- Select --";

        jLocationComboBox.setModel(new DefaultComboBoxModel(location));
        jLocationComboBox.setSelectedItem("-- Select --");
    }
     void resetCategory()
    {
        String[] category=systems.getTableDataArray(OpenMSApp.Database_A,"ItemCategory",2);
        category[0]="-- Select --";

        jCategoryComboBox.setModel(new DefaultComboBoxModel(category));
        jCategoryComboBox.setSelectedItem("-- Select --");
    }
     void resetItemCode()
    {
        systems=new Systems();
        String[] itemCode=systems.getTableDataArray(OpenMSApp.Database_A,"Item",1);
        itemCode[0]="-- Select --";

        itemCodeComboBox.setModel(new DefaultComboBoxModel(itemCode));
    }
     void resetFields()
    {
            disableFields();
            jDescriptionTextArea.setText("");
            jNameTextField.setText("");
            jTypeTextField.setText("");
            jPriceTextField.setText("");
            resetCombo();
    }
     void reset()
    {
        resetFields();
        resetCheckBoxes();
    }
     void resetCombo()
    {
        resetLocation();
        resetCategory();
        resetItemCode();
    }
     void disableFields()
    {
            jDescriptionTextArea.setEnabled(false);
            jDescriptionTextArea.setEditable(false);

            jNameTextField.setEnabled(false);
            jNameTextField.setEditable(false);

            jTypeTextField.setEnabled(false);
            jTypeTextField.setEditable(false);

            jPriceTextField.setEnabled(false);
            jPriceTextField.setEditable(false);

            jLocationComboBox.setEnabled(false);
            jLocationComboBox.setEditable(false);

            jCategoryComboBox.setEnabled(false);
            jCategoryComboBox.setEditable(false);
            
            jTaxTextField.setEnabled(false);
            jTaxTextField.setEditable(false);
    }
    private void disableControls()
    {
        jDescriptionTextArea.setEnabled(false);
        jDescriptionTextArea.setEditable(false);

        jPriceTextField.setEnabled(false);
        jPriceTextField.setEditable(false);

        jLocationComboBox.setEnabled(false);
        jLocationComboBox.setEditable(false);

        jTaxTextField.setEnabled(false);
        jTaxTextField.setEditable(false);

        itemCodeComboBox.setEnabled(false);
        jUpdateButton.setEnabled(false);
        
        jCheckBox2.setEnabled(false);
        jCheckBox3.setEnabled(false);
        jCheckBox5.setEnabled(false);
        jCheckBox4.setEnabled(false);
    }
    private void enableControls()
    {
        jCheckBox2.setEnabled(true);
        jCheckBox3.setEnabled(true);
        jCheckBox5.setEnabled(true);
        jCheckBox4.setEnabled(true);
        
        if(jCheckBox2.isSelected())
        {
            jDescriptionTextArea.setEnabled(true);
            jDescriptionTextArea.setEditable(true);
        }

        if(jCheckBox3.isSelected())
        {
            jPriceTextField.setEnabled(true);
            jPriceTextField.setEditable(true);
        }
        if(jCheckBox5.isSelected())
        {
            jLocationComboBox.setEnabled(true);
        }

        if(jCheckBox4.isSelected())
        {
            jTaxTextField.setEnabled(true);
            jTaxTextField.setEditable(true);
        }
            
        itemCodeComboBox.setEnabled(true);
        jUpdateButton.setEnabled(true);
        this.setTitle("::. Edit Item");
    }
     boolean isCheckBoxesFalse()
    {
        boolean state = true;
        if((!jCheckBox2.isSelected())&&(!jCheckBox3.isSelected())&&(!jCheckBox5.isSelected())&&(!jCheckBox4.isSelected()))
        {
            state=false;
        }

        return state;
    }
     void resetCheckBoxes()
    {
        jCheckBox2.setSelected(false);
        jCheckBox3.setSelected(false);
        jCheckBox5.setSelected(false);
        jCheckBox4.setSelected(false);

    }

     String getDbLocation(String locationName)
    {
        if(locationName.isEmpty())
        {
            locationName="-- Select --";
        }
        return locationName;
    }
     String getItemLocation()
    {
        String location=String.valueOf(jLocationComboBox.getSelectedItem());

        if(location.equals("-- Select --"))
        {
            location="";

        }
        return location;
    }
    private void submitData()
    {
        //Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+"  prnUpdItem"+Connect.procInitStart+"?,?,?,?,?"+Connect.procInitEnd);
            try{
            statement.setString(1,itemCodeComboBox.getSelectedItem().toString());
            statement.setString(2,jDescriptionTextArea.getText());
            statement.setString(3,getItemLocation());
            statement.setString(4,jPriceTextField.getText());
            statement.setString(5,jTaxTextField.getText());
            }
            catch(Exception e)
            {
            System.out.println("EditItem.submitData() gave error ! "+e);
            }
        Connect.alert="Y";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox itemCodeComboBox;
    private javax.swing.JLabel jAddressLabel;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jCategoryComboBox;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JTextArea jDescriptionTextArea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JComboBox jLocationComboBox;
    private javax.swing.JTextField jNameTextField;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jPriceTextField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTaxTextField;
    private javax.swing.JTextField jTypeTextField;
    private javax.swing.JButton jUpdateButton;
    // End of variables declaration//GEN-END:variables

}
